package com.kailong.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.db.Session;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/imageGenerate")
public class ImageGenerate extends HttpServlet {
    public void doGet (HttpServletRequest request,HttpServletResponse response) {
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(80,20,4,25);
        response.setContentType("image/jpeg");
        response.setHeader("Pragma", "No-cache");
        try{
            lineCaptcha.write(response.getOutputStream());
            String code = lineCaptcha.getCode();
            request.getSession().setAttribute("piccode",code);
            response.getOutputStream().close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}